home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-11 | 2.5 KB | 125 lines | [TEXT/PJMM] |
- unit MyAssocStrings;
-
- interface
-
- procedure AssocCreate (var h: handle);
- procedure AssocDestroy (var h: handle);
- function AssocCount (h: handle): longInt;
- procedure AssocGetIndexedKey (h: handle; index: longInt; var key, data: str255);
- procedure AssocGet (h: handle; key: str255; var data: str255);
- procedure AssocSet (h: handle; key, data: str255);
-
- implementation
-
- uses
- QLowLevel;
-
- function GetByte (p: univ Ptr; offset: longint): integer;
- inline
- $201F, $D09F, $2040, $4240, $1010, $3E80;
-
- procedure AssocCreate (var h: handle);
- begin
- h := NewHandle(0);
- end;
-
- procedure AssocDestroy (var h: handle);
- begin
- DisposeHandle(h);
- h := nil;
- end;
-
- procedure Next (h: handle; var pos: longInt);
- begin
- pos := pos + GetByte(h^, pos) + 1;
- end;
-
- procedure CopyString (h: handle; pos: longInt; var s: str255);
- begin
- BlockMove(AddPtrLong(h^, pos), @s, GetByte(h^, pos) + 1);
- end;
-
- function AssocCount (h: handle): longInt;
- var
- pos, size: longInt;
- count: longInt;
- begin
- count := 0;
- size := GetHandleSize(h);
- pos := 0;
- while pos < size do begin
- Next(h, pos);
- Next(h, pos);
- count := count + 1;
- end;
- AssocCount := count;
- end;
-
- procedure AssocGetIndexedKey (h: handle; index: longInt; var key, data: str255);
- var
- pos, size: longInt;
- begin
- size := GetHandleSize(h);
- pos := 0;
- while (pos < size) & (index > 1) do begin
- Next(h, pos);
- Next(h, pos);
- index := index - 1;
- end;
- if (pos < size) & (index = 1) then begin
- CopyString(h, pos, key);
- Next(h, pos);
- CopyString(h, pos, data);
- end
- else begin
- key := '';
- data := '';
- end;
- end;
-
- function GetPos (h: handle; var key: str255; var pos: longInt): boolean;
- var
- size: longInt;
- thiskey: str255;
- begin
- GetPos := false;
- size := GetHandleSize(h);
- pos := 0;
- while pos < size do begin
- CopyString(h, pos, thiskey);
- if IUEqualString(thiskey, key) = 0 then begin
- GetPos := true;
- leave;
- end;
- Next(h, pos);
- Next(h, pos);
- end;
- end;
-
- procedure AssocGet (h: handle; key: str255; var data: str255);
- var
- pos: longInt;
- begin
- data := '';
- if GetPos(h, key, pos) then begin
- Next(h, pos);
- CopyString(h, pos, data);
- end;
- end;
-
- procedure AssocSet (h: handle; key, data: str255);
- var
- err: OSErr;
- pos: longInt;
- begin
- if GetPos(h, key, pos) then begin
- Next(h, pos);
- pos := Munger(h, pos, nil, GetByte(h^, pos) + 1, @data, length(data) + 1);
- end
- else begin
- err := PtrAndHand(@key, h, length(key) + 1);
- err := PtrAndHand(@data, h, length(data) + 1);
- end;
- end;
-
- end.